﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Controls;

namespace TestingApp.Services {
    public class PageService {

        private Stack<Type> _history;

        public bool CanGoToBack => _history.Skip(1).Any();
        public event Action<Page> OnPageChanged;

        public PageService()  {
            _history = new Stack<Type>();
        }

        public void Navigate(Page page) {
            OnPageChanged?.Invoke(page);        
            _history.Push(page.GetType());         
        }

        internal void GoToBack() {

            _history.Pop();
            var page = _history.Peek();
            OnPageChanged?.Invoke( (Page)Activator.CreateInstance(page));            
        }
    }
}
